$(function () {
    $('.class-set-dissolve-right input').on('click', function () {
        // console.log(1)
        if ($(this).prop('checked') == true) {
            $('.class-set-dissolve-button').show('fast');
        } else {
            $('.class-set-dissolve-button').hide('fast');
        }
    });
    $('#btn').on('click', function () {
        if ($(this).prop('checked') == true) {
            $('.class-set-score-job-content').show('slow');
        } else {
            $('.class-set-score-job-content').hide('slow');
        }
    });
    // ====================================================================
    // ajax部分
    // 上传头像
    $('#avatar').change(function () {
        // console.log(1)
        // 实例化FormData
        let formData = new FormData();
        let file = $(this)[0].files[0];
        // console.log(file)
        formData.append('avatar', file);
        // console.log(formData);
        // 发起ajax请求
        $.ajax({
            type: 'post',
            url: '/classUpload',
            data: formData,
            contentType: false,
            processData: false,
            success: function (data) {
                let avatarHtml = template('class-avatar-template', data);
                // console.log(data)
                $('.profile-photo').html(avatarHtml);
            }
        })
    })
    // 修改班级信息
    $('#btn-add').click(function () {
        // console.log(2);
        let id = $(this).data('id');
        let formData = $('form').serialize();
        $.ajax({
            type: 'post',
            url: '/updateClass',
            data: formData + '&id=' + id,
            success: function (data) {
                if (data.code == '100') {
                    alert(data.message);
                    location.href = '/classInformation'
                }
            }
        })
    })
})